<!--# layout("/common/layout.html",{"jsBase":"/js/admin/user/"}){ -->

<form class="layui-form " id="changePasswordForm"
	>
	<div class="layui-row">
		<div class="layui-form-item">
			<label class="layui-form-label">用户姓名</label>
            <div class="layui-input-inline">
				<input type="text" name="name" disabled autocomplete="off"
					class="layui-input" value="${user.name}">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">登录账号</label>
			<div class="layui-input-inline">
				<input type="text" name="code" disabled 
					placeholder="请输入" autocomplete="off" class="layui-input"
					value="${user.code}">
			</div>
		</div>
	</div>
	<div class="layui-row">
		<div class="layui-form-item">
			<label class="layui-form-label">原密码</label>
			<div class="layui-input-inline">
				<input type="password" name="password_old" autocomplete="off" lay-verify="required"
					   placeholder="请输入密码" class="layui-input" id="password_old" value="">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-inline">
				<input type="password" name="password" autocomplete="off" lay-verify="required"
					placeholder="请输入密码" class="layui-input" id="password" value="">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">确认密码</label>
			<div class="layui-input-inline">
				<input type="password" name="password2" lay-verify="required"
					placeholder="请再次输入密码" autocomplete="off" id="password2" class="layui-input"
					>
			</div>
		</div>
		<div class="layui-form-item" style="text-align: center;">
			<span style="margin-left:170px;">密码必须是8-16位的数字、字符组合(不能是纯数字)</span>
		</div>
	</div>

    <div class="layui-form-item" style="text-align: center;">
        <button class="layui-btn layui-btn-danger" type="button"  lay-submit lay-filter="form">保存</button>
        <button class="layui-btn" type="button" id="savePassword-cancel">取消</button>
    </div>	<input type="hidden" name="id" value=${user.id} />
</form>
<!--#} -->
<script>
layui.use(['form'], function(){
    var form = layui.form;
    form.on('submit(form)', function() {
        var callback = function(){
            Common.info("密码更改成功");
            //Lib.closeFrame();
			//window.location.reload();
			var index = parent.layer.getFrameIndex(window.name);
			//parent.location.reload(); //刷新父页面
			parent.layer.close(index);
        };
        //校验密码：只能输入8-16个字母、数字、下划线
        var passwordOld = $("#password_old").val();
        var passwordNew = $("#password").val();
        var reg3 = /^(?=.{8,16})(?=.*[a-z])(?=.*\d).*$/;
        if(passwordNew.length < 8 || passwordNew.length > 16){
            Common.info("新密码长度需要8-16位");
            return;
        }else if(!reg3.test(passwordNew)){
            Common.info("新密码必需含有数字和字母");
            return;
        }
        if($("#password").val() == $("#password2").val()) {
            Lib.submitForm("/cms/common/changePassword.json", $('#changePasswordForm'), {},
                callback);
        }else {
            Common.info("2次密码不一致");
		}
    })
    $("#savePassword-cancel").click(function(){
        Lib.closeFrame();
    });


});
</script>

